package com.room.controller.room;

import com.room.mapper.BedroomMapper;
import com.room.pojo.Bedroom;
import com.room.pojo.DormResult;
import com.room.service.BedroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @创建人 lin
 * @创建时间 2019/10/14
 * @描述
 */
@RequestMapping("/bedroom/manager")
@RestController
public class BedroomController {

    @Autowired
    public BedroomService bedroomService;

    @RequestMapping(value = "/getBedroomByApaId" ,method = RequestMethod.GET)
    public List<Bedroom> getBedroomByApartId(String apartmentId){
        return bedroomService.getBedroomByApartId(apartmentId);
    }

    /**
     * 添加宿舍
     * @param bedroom
     * @return
     */
    @RequestMapping(value = "/bedroom",method = RequestMethod.POST)
    public DormResult addBedroom(Bedroom bedroom){
        String maxId = null;
        if(bedroomService.getMaxId()==null){
            maxId = "1";
        }else{
            maxId = bedroomService.getMaxId();
            int a = Integer.parseInt(maxId);
            ++a;
            maxId = String.valueOf(a);
        }
        bedroom.setBedroomId(maxId);
        bedroom.setStatus("N");
        bedroom.setTotalBed("0/5");
        if(bedroomService.addBedroom(bedroom)==1){
            return DormResult.ok("添加成功");
        }
        return DormResult.error("添加失败");
    }
}
